## Process this file with automake to produce Makefile.in
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright © 2000-2012 Free Software Foundation, Inc.
# Copyright © 2020-2022 GNUnet e.V.
#
# Author (GnuTLS): Nikos Mavrogiannopoulos
# Author (scheme-GNUnet): Maxime Devos
#
# This file was part of scheme-GNUnet.
#
# scheme-GNUnet is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# scheme-GNUnet is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with scheme-GNUnet.  If not, see <http://www.gnu.org/licenses/>.

# This file is partially based upon guile/Makefile.am in GnuTLS.
# Not all scheme-GNUnet code is licensed as GPL, some is licensed as AGPL.

ACLOCAL_AMFLAGS = -I m4
AM_CPPFLAGS = -I$(top_srcdir)/include
SUFFIXES = .scm .go

# These scripts are more of a demo than something
# that actually works, so don't compile or install
# them.
#
# gnu/gnunet/scripts/download-store.scm
# gnu/gnunet/scripts/publish-store.scm
# gnu/gnunet/scripts/guix-stuff.scm

# Scheme code that works
modules = \
  web/form.scm \
  \
  gnu/extractor/enum.scm \
  \
  \
  gnu/gnunet/message/protocols.scm \
  \
  gnu/gnunet/concurrency/update.scm \
  gnu/gnunet/concurrency/repeated-condition.scm \
  gnu/gnunet/concurrency/lost-and-found.scm \
  \
  gnu/gnunet/mq/envelope.scm \
  gnu/gnunet/mq/error-reporting.scm \
  gnu/gnunet/mq/handler.scm \
  gnu/gnunet/mq/prio-prefs.scm \
  gnu/gnunet/mq/prio-prefs2.scm \
  gnu/gnunet/mq.scm \
  \
  gnu/gnunet/mq-impl/stream.scm \
  \
  gnu/gnunet/utils/bv-slice.scm \
  gnu/gnunet/utils/hat-let.scm \
  gnu/gnunet/utils/cut-syntax.scm \
  gnu/gnunet/utils/netstruct.scm \
  gnu/gnunet/utils/platform-enum.scm \
  gnu/gnunet/utils/tokeniser.scm \
  \
  gnu/gnunet/block.scm \
  \
  gnu/gnunet/cadet/client.scm \
  gnu/gnunet/cadet/network.scm \
  gnu/gnunet/cadet/struct.scm \
  \
  gnu/gnunet/config/parser.scm \
  gnu/gnunet/config/value-parser.scm \
  gnu/gnunet/config/expand.scm \
  gnu/gnunet/config/db.scm \
  gnu/gnunet/config/fs.scm \
  \
  gnu/gnunet/crypto.scm \
  gnu/gnunet/crypto/struct.scm \
  \
  gnu/gnunet/dht/client.scm \
  gnu/gnunet/dht/network.scm \
  gnu/gnunet/dht/struct.scm \
  \
  gnu/gnunet/util/cmsg.scm \
  gnu/gnunet/util/time.scm \
  gnu/gnunet/icmp/struct.scm \
  \
  gnu/gnunet/util/struct.scm \
  gnu/gnunet/hashcode/struct.scm \
  \
  gnu/gnunet/nse/client.scm \
  gnu/gnunet/nse/struct.scm \
  \
  gnu/gnunet/netstruct/procedural.scm \
  gnu/gnunet/netstruct/syntactic.scm \
  \
  gnu/gnunet/server.scm

GOBJECTS = $(modules:%.scm=%.go)
nobase_dist_guilesite_DATA = $(modules) gnu/gnunet/config/default.conf

E = gnu/gnunet/message/enum-
scmfrags = \
  gnu/gnunet/message/protocols.scmgen \
  $(E)agpl.scmfrag \
  $(E)arm.scmfrag \
  $(E)ats.scmfrag \
  $(E)cadet.scmfrag \
  $(E)chat.scmfrag \
  $(E)consensus.scmfrag \
  $(E)conversation.scmfrag \
  $(E)core.scmfrag \
  $(E)datastore.scmfrag \
  $(E)dht.scmfrag \
  $(E)fragment.scmfrag \
  $(E)fs-publish.scmfrag \
  $(E)fs.scmfrag \
  $(E)gns.scmfrag \
  $(E)hello.scmfrag \
  $(E)identity.scmfrag \
  $(E)lockmanager.scmfrag \
  $(E)multicast.scmfrag \
  $(E)namecache.scmfrag \
  $(E)namestore.scmfrag \
  $(E)nse.scmfrag \
  $(E)peerinfo.scmfrag \
  $(E)psyc.scmfrag \
  $(E)psycstore.scmfrag \
  $(E)regex.scmfrag \
  $(E)resolver.scmfrag \
  $(E)revocation.scmfrag \
  $(E)scalarproduct.scmfrag \
  $(E)set.scmfrag \
  $(E)statistics.scmfrag \
  $(E)testbed.scmfrag \
  $(E)transport-dv.scmfrag \
  $(E)transport.scmfrag \
  $(E)util.scmfrag \
  $(E)vpn-dns.scmfrag \
  $(E)vpn.scmfrag \
  $(E)wlan.scmfrag

nobase_dist_guilesite_DATA += $(scmfrags)

# Recompile protocols.go whenever one of the scmfrag files change.
gnu/gnunet/message/protocols.go : $(scmfrags)

# Scheme code compilation
nobase_nodist_guilesiteccache_DATA = $(GOBJECTS)

# Do not unset 'GUILE_LOAD_COMPILED_PATH', as guile-pfds as installed
# in Guix does not have .scm files (but it does in Guile).
# XXX: Use the C locale for when Guile lacks
# <https://git.sv.gnu.org/cgit/guile.git/commit/?h=stable-2.0&id=e2c6bf3866d1186c60bacfbd4fe5037087ee5e3f>.
%.go: %.scm
	$(AM_V_GUILEC)$(MKDIR_P) "`dirname "$@"`" ;			\
	$(AM_V_P) && out=1 || out=- ;					\
	LC_ALL=C							\
	builddir="$(top_builddir)"					\
	GUILE_AUTO_COMPILE=0						\
	$(GUILD) compile -O2 --target="$(host)"				\
	  -L "$(top_srcdir)"						\
	  -Wformat -Wunbound-variable -Warity-mismatch			\
	  -o "$@" "$<" >&$$out

TEST_EXTENSIONS = .scm
TESTS =

# Scheme tests
# FIXME ./pre-inst-env & ./test-env
#
# Set --auto-compile, because ‘tests/envelope.scm - references dropped after
# sent’ requires optimisation to avoid keeping references.  Set XDG_CACHE_HOME
# because $HOME may be unwritable and to reduce clutter.
SCM_LOG_DRIVER = \
  env XDG_CACHE_HOME="$(abs_builddir)" $(GUILE) --auto-compile -L \
    $(top_srcdir) -C $(top_builddir) -e main \
    $(top_srcdir)/build-aux/test-driver.scm

SCM_TESTS = \
  tests/envelope.scm \
  tests/error-reporting.scm \
  tests/message-handler.scm \
  tests/mq.scm \
  tests/mq-stream.scm \
  tests/network-size.scm \
  tests/update.scm \
  tests/repeated-condition.scm \
  tests/bv-slice.scm \
  tests/cmsg.scm \
  tests/config-parser.scm \
  tests/config-value-parser.scm \
  tests/config-expand.scm \
  tests/config-db.scm \
  tests/config-fs.scm \
  tests/cadet.scm \
  tests/crypto.scm \
  tests/distributed-hash-table.scm \
  tests/form.scm \
  tests/lost-and-found.scm \
  tests/netstruct.scm \
  tests/time.scm \
  tests/tokeniser.scm

SCM_TESTS_ENVIRONMENT = \
  GUILE_AUTO_COMPILE=0 \
  GUILE_WARN_DEPRECATED=detailed
TESTS += $(SCM_TESTS)
EXTRA_DIST = $(SCM_TESTS) tests/utils.scm build-aux/test-driver.scm

# For documentation (TODO regenerate indices).
# Set HOME to avoid interfering with the user's TeXmacs
# configuration and because HOME can be unwritable.
#
# --auto-servernum is required to let multiple xvfb-run
# run concurrently.
TEXMACS_CONVERT = env "HOME=$(abs_builddir)" xvfb-run --auto-servernum -- texmacs
# Use MathML for formulae instead of PNG images.
# While the images are prettier than the rendering by the browser,
# they aren't accessible and it is somewhat difficult to tell Automake
# to install the PNG images.
TEXMACS_HTML_SETTINGS = \
  '(set-boolean-preference "texmacs->html:images" \#f)\
   (set-boolean-preference "texmacs->html:mathjax" \#f)\
   (set-boolean-preference "texmacs->html:mathml" \#t)'

tm_fragments = \
  doc/configuration.tm doc/contributing.tm doc/distributed-hash-table.tm \
  doc/network-size-estimation.tm doc/network-structures.tm \
  doc/service-communication.tm

doc/scheme-gnunet.pdf: doc/scheme-gnunet.tm $(tm_fragments)
	$(TEXMACS_CONVERT) -c "$<" "$@" -q
doc/scheme-gnunet.html: doc/scheme-gnunet.tm $(tm_fragments)
	$(TEXMACS_CONVERT) -x $(TEXMACS_HTML_SETTINGS) -c "$<" "$@" -q

dist_doc_DATA = doc/scheme-gnunet.tm $(tm_fragments) doc/fdl.tm
nobase_dist_doc_DATA = examples/web.scm
nodist_html_DATA = doc/scheme-gnunet.html
nodist_pdf_DATA = doc/scheme-gnunet.pdf

clean-local:
	rm -f $(GOBJECTS)
